/**
 * 普通员工类（按小时计薪）
 */
class RegularEmployee extends Employee {
    private double hourlyRate;   // 时薪
    private double workingHours; // 工作时长（小时）

    // 构造方法
    public RegularEmployee(String name, String empId, String username, String password,
                           double hourlyRate, double workingHours) {
        super(name, empId, username, password);
        this.hourlyRate = hourlyRate;
        this.workingHours = workingHours;
    }

    // 计算薪资（校验工作时长合理性）
    @Override
    public double calculateSalary() throws InvalidWorkingHoursException {
        if (workingHours < 0 || workingHours > 168) { // 一周最大168小时
            throw new InvalidWorkingHoursException("工作时长异常，有效范围为0-168小时");
        }
        return hourlyRate * workingHours;
    }

    // 生成工资条
    @Override
    public String generatePaySlip() {
        try {
            return "工资条\n" +
                    "员工姓名：" + name + "\n" +
                    "工号：" + empId + "\n" +
                    "员工类型：普通员工\n" +
                    "时薪：" + hourlyRate + "元\n" +
                    "工作时长：" + workingHours + "小时\n" +
                    "本月薪资：" + calculateSalary() + "元";
        } catch (InvalidWorkingHoursException e) {
            return "工资条生成失败：" + e.getMessage();
        }
    }

    // 修改工作时长（可选功能）
    public void setWorkingHours(double workingHours) { this.workingHours = workingHours; }
}